Skip to content

[Translatable] Add methods to remove translations by entity, by field or by locale#3030

Open
kevinkopf wants to merge 1 commit into
doctrine-extensions:mainfrom
kevinkopf:translatable-remove-methods
Open

[Translatable] Add methods to remove translations by entity, by field or by locale#3030
kevinkopf wants to merge 1 commit into
doctrine-extensions:mainfrom
kevinkopf:translatable-remove-methods

Conversation

@kevinkopf

@kevinkopf kevinkopf commented Jan 17, 2026

Copy link
Copy Markdown

I have found myself in the situation when I needed to find and remove translations. One of the specific use cases goes like this:

  1. Create a TranslationEntity
#[ORM\Table(name: 'article_translations')]
#[ORM\Index(name: 'article_translation_idx', columns: ['foreign_key', 'locale', 'object_class', 'field'])]
#[ORM\Entity(repositoryClass: TranslationRepository::class)]
class ArticleTranslation extends AbstractTranslation
{
    /**
     * All required columns are mapped through inherited superclass
     */
}
  1. Set up the TranslatinoRepository (I do it in Symfony services as per docs)
# services.yaml

  Gedmo\Translatable\Entity\Repository\TranslationRepository:
    factory: [ '@doctrine.orm.entity_manager', 'getRepository' ]
    arguments:
      - 'Gedmo\Translatable\Entity\Translation'
  1. Inject the repository and try to translate:
class SomeHandler
{
  public function __construct() {
    private TranslationRepository $translationRepository,
  }

  public function handle(...) {
    $this->translationRepository->translate($entity, "field", $locale, "Some value");
  }
}

When run multiple times, I end up with multiple translations in the database.

I believe, article_translation_idx should be UniqueConstraint instead of Index, but I decided to introduce the missing removal method before digging deeper into this.

@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions Bot added the Stale label Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant